package qz_rpt

import com.tsqc.system.util.table.TranposUtils

class PartFinController {
    def dynamicQueryService
    def partFin() {
        def pageCurrent = params.pageCurrent ? Integer.parseInt(params.pageCurrent) : 1
        def pageSize = params.pageSize ? Integer.parseInt(params.pageSize) : 10
        params.startno = (pageSize * (pageCurrent - 1)) + 1
        params.endno = pageSize * pageCurrent
        def partFinSum=[]
        def tableHeadList=[]
        def partFinList=[]
        def list=[]
        def pageSizeList = [10,20,50,100]
        def totalCount =0
        def orderStatusAnalysisStartedList=[]
        params.SYS_QUERY_NAME = 'partFinDetailCate'
        def partFinDetailCate = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'partFinTotalGroup'
        def partFinTotalGroup = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'orderStatusAnalysisStartedList'
        orderStatusAnalysisStartedList = dynamicQueryService.queryForList(params)
        if(params.EXPORT_CONTENT_NAME=='Excel'){
            params.SYS_QUERY_NAME = 'partFinList'
            partFinList = dynamicQueryService.queryForList(params)
            list=TranposUtils.colToRow('STEP_DESC','STEP_QTY',partFinList)

            if (list.size() > 0) {
                tableHeadList = list[0].keySet()
                totalCount =1
            }else{
                totalCount =0
            }

//            params.SYS_QUERY_NAME = 'orderStatusAnalysisCount'
//            totalCount = dynamicQueryService.queryForList(params)[0].TOTALCOUNT
//            params.SYS_QUERY_NAME = 'orderStatusAnalysisSum'
//            orderStatusAnalysisSum = dynamicQueryService.queryForList(params)

        }
        println(params.docId)
        print(params.startedState)
        [pageSize     : pageSize, totalCount: totalCount, pageSizeList: pageSizeList,pageCurrent:pageCurrent,partFinDetailCate:partFinDetailCate,docId:params.docId?:'',
         partFinSum:partFinSum,tableHeadList:tableHeadList,partFinList:partFinList,list:list,group3:params.group3?:'',partFinTotalGroup:partFinTotalGroup,orderStatusAnalysisStartedList:orderStatusAnalysisStartedList,
         startTime:params.startTime,endTime:params.endTime,partName:params.partName,partDesc:params.partDesc?:'',totalGroup:params.totalGroup?:'',detailCate:params.detailCate?:'',startedState:params.startedState?:'']
    }

    def partFinStep(){
        def pageCurrent = params.pageCurrent ? Integer.parseInt(params.pageCurrent) : 1
        def pageSize = params.pageSize ? Integer.parseInt(params.pageSize) : 10
        params.startno = (pageSize * (pageCurrent - 1)) + 1
        params.endno = pageSize * pageCurrent
        def pageSizeList = [10,20,50,100]
        def tableHeadList=[]
        println("123")
        params.SYS_QUERY_NAME = 'partFinStep'
        def partFinStep = dynamicQueryService.queryForList(params)
        if (partFinStep.size() > 0) {
            tableHeadList = partFinStep[0].keySet()
        }
        params.SYS_QUERY_NAME = 'partFinStepCount'
        def totalCount = dynamicQueryService.queryForList(params)[0].TOTALCOUNT

        [startno:params.startno?:'',endno:params.endno?:'',pageSize     : pageSize, totalCount: totalCount, pageSizeList: pageSizeList,pageCurrent:pageCurrent
         ,tableHeadList:tableHeadList,partFinStep:partFinStep,
         startTime:params.startTime?:'',endTime:params.endTime?:'',partName1:params.partName1,stepName1:params.stepName1,
         lotId:params.lotId,jiagongBy:params.jiagongBy?:'']
    }
}
